<template>
    <div class="goods-list">
        <div class="goods-item" v-for="(item,index) in goodsList" :key="index">
            <router-link :to=" '/home/goodsinfo?id='+ item.id ">
                <img :src="item.pic" alt="">
            <div class="title">{{item.title}}</div>
            <div class="info">
                <p class="price">
                    <span class="now">￥{{item.price}}</span>
                    <span class="old">￥{{item.old}}</span>
                </p>
                <p class="sell">
                    <span>热卖中</span>
                    <span>销量:{{item.sale}}</span>
                </p>
            </div>
            </router-link>
        </div>
    </div>
</template>

<script>
export default {
    data() {
        return {
            goodsList:[]
        }
    },
    methods: {
        getGoodsList(){
            this.axios({
                url:"http://10.31.162.198/1810-3/Vue/vue-cms/src/lib/PHP/goods.php"
            }).then(res=>{
                this.goodsList=res.data;
                // console.log(this.goodsList)
            })
        }
    },
    created(){
        this.getGoodsList()
    }
}
</script>

<style lang="scss" scoped>
.goods-list{
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    padding: 0 6px;
    .goods-item{
        width: 49%;
        border: 1px solid #ccc;
        box-shadow: 0 0 8px #ccc;
        margin: 3px 0;
        padding: 2px;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        img{
            width: 100%;
        }
        .title{
            font-size: 13px;
        }
        .info{
            background-color: #eee;
            p{
                margin: 0;
                padding: 5px;
            }
            .price{
                .now{
                    color: #f00;
                    font-size: 14px;
                    font-weight: bold;
                }
                .old{
                    text-decoration: line-through;
                    font-size: 12px;
                    margin-left: 10px;
                }
            }
            .sell{
                display: flex;
                justify-content: space-between;
                font-size: 12px;
            }
        }
    }
}
</style>
